<?php

define('ACC', true);
require ('../includes/init.php');
$usermodel = new AdminUserModel();

if($_GET['act'] == 'edit'){
	
	$user = $usermodel->getUser($_SESSION['username']);
	
	$smarty->assign('user', $user);
	$smarty->assign('action', 'modify');
	$smarty->assign('title', '编辑个人资料');
	$smarty->assign('url', 'manager.php?act=list');
	$smarty->assign('link', '管理员列表');
	
	$smarty->display('./admin/account.html');
	
}else if($_GET['act'] == 'update'){
	
	$user = $usermodel->getUser($_SESSION['username']);

	$data['username'] = trim($_POST['username']);
	$data['email'] = trim($_POST['email']);
	$old_password = trim($_POST['old_password']);
	
	if($user['password'] != md5($old_password)){
		$desc = '旧密码填写错误！';
		$url = 'account.php?act=edit';
		$link = '编辑个人资料';
		admin_msg($smarty, $desc, $url, $link);
		exit;
	}
	
	$password = trim($_POST['password']);
	$pwd_confirm = trim($_POST['pwd_confirm']);
	if($password == ''){
		echo '密码不能为空！';
		exit;
	}
	if($password != $pwd_confirm){
		$desc = '两次密码不一致！';
		$url = 'account.php?act=edit';
		$link = '编辑个人资料';
		admin_msg($smarty, $desc, $url, $link);
		exit;
	}
	$data['password'] = md5($password);
	
	if($usermodel->update($data, $user['user_id'])){
		$user = $usermodel->getUser($_SESSION['username']);
		$_SESSION['username'] = $user['username'];
		$desc = '修改信息成功';
		$url = 'account.php?act=message';
		$link = '个人信息';
		admin_msg($smarty, $desc, $url, $link);
	}else{
		echo '修改信息失败!';
		exit;
	}
	
}else if($_GET['act'] == 'message'){
	
	$user = $usermodel->getUser($_SESSION['username']);
	
	$smarty->assign('user', $user);
	$smarty->assign('action', 'message');
	$smarty->assign('title', '编辑个人资料');
	$smarty->assign('url', 'manager.php?act=list');
	$smarty->assign('link', '管理员列表');
	
	$smarty->display('./admin/account.html');
	
}









?>